package mwa.cs.dao;

import java.util.Map;

import mwa.cs.database.Database;
import mwa.cs.model.ReceivePosition;

public class ReceivePositionDAO {
	private Database db;
	
	public ReceivePositionDAO(Database db){
		this.db = db;
	}
	
	
	 //get resivePositon 
	  public Map<String, Object> findReceivePositonBySiteId(int pnSiteId) {
	        String vaSql = "SELECT * FROM receive_position WHERE site_id = ?";
	        Map<String, Object> result = db.querySingle(vaSql,pnSiteId);
	        if (result != null) {
	            return result;
	        } else {
	            return null;
	        }
	    }
	  
	  
	  //insert receive_position 
	  public void addReceivePosition(ReceivePosition poReceivePosition) {
	    	 String vaSql = "INSERT INTO RECEIVE_POSITION (SITE_ID,EMPLOYEE_NAME,EMPLOYEE_POSITION,HEAD_NAME,HEAD_POSITION,"
	    			 						+ "INSERT_USER_ID,INSERT_DATE,INSERT_TIME,"
	    	 								+ "UPDATE_USER_ID,UPDATE_DATE,UPDATE_TIME)"
	    			 						+"VALUES(?,?,?,?,?,?,?,?,?,?,?)";
	    			try {
	    					db.insert(vaSql, poReceivePosition.getVnSiteId(),
	    							poReceivePosition.getVaEmName(),
	    							poReceivePosition.getVaEmPosition(),
	    							poReceivePosition.getVaHeadName(),
	    							poReceivePosition.getVaHeadPosition(),
	    							poReceivePosition.getVnInsertUserId(),
	    							poReceivePosition.getVaInsertDate(),
	    							poReceivePosition.getVaInsertTime(),
	    							poReceivePosition.getVnUpdateUserId(),
	    							poReceivePosition.getVaUpdateDate(),
	    							poReceivePosition.getVaUpdateTime());
	    				
	    			}catch (Exception e) {
	    	        	throw new RuntimeException(e);
	    	        }
	    	}
	   
	  //update receive_position
	  public void updateReceivePosition(int pnSiteId,ReceivePosition poReceivePosition) {
 	 	 
	    	String vaSql  = " UPDATE RECEIVE_POSITION SET " +
	    				  " EMPLOYEE_NAME = ? , " +
	    				  " EMPLOYEE_POSITION  = ? , " +
	    				  " HEAD_NAME  = ? , " +
	    				  " HEAD_POSITION  = ? , " +
	    				  " UPDATE_USER_ID = ? , "+
	    				  " UPDATE_DATE = ? , " +
	    				  " UPDATE_TIME = ? " +
	    				  " WHERE " + 
	    				  " SITE_ID = ? ";
	    	
	    	 try {
					db.update(vaSql, poReceivePosition.getVaEmName() , 
							poReceivePosition.getVaEmPosition(),
							poReceivePosition.getVaHeadName(),
							poReceivePosition.getVaHeadPosition(),
							poReceivePosition.getVnUpdateUserId(),
							poReceivePosition.getVaUpdateDate(),
							poReceivePosition.getVaUpdateTime(),
							pnSiteId);
								
			}catch (Exception e) {
				throw new RuntimeException(e);
			}
	    }
	  
}
